import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import goods from './goods'


Vue.use(Router)


export const constantRoutes = [
    {
        path:'/',
        component:Layout,
        children:[
            {
                path: '',
                redirect: { name: 'bannerManage' },
            },
            goods,// 商品
        ]
    }
];


const createRouter = () => new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher;
}

// 解决重复点击路由报错
const originalPush = Router.prototype.push
   Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

export default router